package com.lyz.dataStructure.面试算法题.GrowingIO;/**
 * @Author:759057893@qq.com Lyz
 * @Date: ${Date} 11:18
 * @Description:
 **/

/**
 *@Author:759057893@qq.com Lyz
 *@Date: 2019/9/2 11:18
 *@Description:
 **/
/*
懒汉模式
 */
public class Singleton {
    private static  Singleton instance = null;
    private Singleton(){}

    public static   Singleton  getInstance(){
        if(instance==null){
            instance = new Singleton();
        }
        return instance;
    }
}


/*
饿汉模式
 */
class  Singleton1{
    private static Singleton1 instance =new Singleton1();

    private  Singleton1(){}

    public static  Singleton1 getSingleton(){
        return  instance;
    }
}

/*
懒汉双重加锁
 */
class  Singleton2{
    private  static  volatile  Singleton2 instance;
    private  Singleton2(){}

    public  static Singleton2 getInstance(){
        if(instance==null){
            synchronized (Singleton2.class){
                if(instance==null){
                    instance = new Singleton2();
                }
            }
        }
        return instance;
    }
}